TARGET_NAME = sort
#DEFAULT_BUILD_TYPE = debug
DEFAULT_BUILD_TYPE = release
COMPILER = g++
HEADERS =
SOURCES = sort.cpp file_op.hpp logger.hpp
OBJECTS = *.o

# Common options
COMMON_COMPILER_OPTS = 
COMMON_LINKER_OPTS =
COMMON_COMMON_OPTS = -Wall

# Debug options
DEBUG_COMPILER_OPTS = $(COMMON_COMPILER_OPTS)
DEBUG_LINKER_OPTS = $(COMMON_LINKER_OPTS)
DEBUG_COMMON_OPTS = $(COMMON_COMMON_OPTS) -g -O0

# Release options
RELEASE_COMPILER_OPTS = $(COMMON_COMPILER_OPTS)
RELEASE_LINKER_OPTS = $(COMMON_LINKER_OPTS)
RELEASE_COMMON_OPTS = $(COMMON_COMMON_OPTS) -O4

# Debug build steps
DEBUG_BUILD = $(COMPILER) $(DEBUG_COMMON_OPTS) $(DEBUG_COMPILER_OPTS) -c $(SOURCES)
DEBUG_LINK = $(COMPILER) $(DEBUG_COMMON_OPTS) $(DEBUG_LINKER_OPTS) $(OBJECTS) -o $(TARGET_NAME)

# Release build steps
RELEASE_BUILD = $(COMPILER) $(RELEASE_COMMON_OPTS) $(RELEASE_COMPILER_OPTS) -c $(SOURCES)
RELEASE_LINK = $(COMPILER) $(RELEASE_COMMON_OPTS) $(RELEASE_LINKER_OPTS) $(OBJECTS) -o $(TARGET_NAME)

all: $(DEFAULT_BUILD_TYPE)

debug: debug_build debug_link

release: release_build release_link

debug_build: $(HEADERS) $(SOURCES)
	$(DEBUG_BUILD)

debug_link: debug_build
	$(DEBUG_LINK)

release_build: $(HEADERS) $(SOURCES)
	$(RELEASE_BUILD)

release_link: release_build
	$(RELEASE_LINK)

clean:
	rm -rf $(TARGET_NAME)
	rm -rf $(OBJECTS)
